package com.zju.demo.controller;

import com.zju.demo.entities.CommonResult;
import com.zju.demo.entities.Person;
import com.zju.demo.service.impl.PaymentserviceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 况祥彬
 * @date 2020/12/16 22:26
 **/
@RestController
public class PaymentController {
    @Autowired
    private PaymentserviceImpl service;

    @GetMapping("/get/{id}")
    public CommonResult<Person> select(@PathVariable("id") Integer id){
        Person person = service.select(id);
        if(person!=null){
            return new CommonResult(200,"插入成功",person);
        }else {
            return new CommonResult(500,"插入失败",null);
        }
    }

    @GetMapping("/get2")
    public CommonResult<Person> select2(@RequestParam("name") String name){
        Person person = service.selectByname(name);
        if(person!=null){
            return new CommonResult(200,"插入成功",person);
        }else {
            return new CommonResult(500,"插入失败",null);
        }
    }

    @PostMapping("/create")
    public CommonResult create(@RequestBody Person person){
        int result = service.create(person);
        if(result>0){
            return new CommonResult(200,"插入成功",result);
        }else {
            return new CommonResult(500,"插入失败",result);
        }
    }


    @PutMapping("/update")
    public CommonResult update(@RequestBody Person person){
        int result = service.update(person);

        if(result>0){
            return new CommonResult(200,"插入成功",result);
        }else {
            return new CommonResult(500,"插入失败",result);
        }
    }

    @DeleteMapping("/delete")
    public CommonResult delete(@RequestParam("id") Integer id){
        int result = service.delete(id);
        if(result>0){
            return new CommonResult(200,"插入成功",result);
        }else {
            return new CommonResult(500,"插入失败",result);
        }
    }

}
